#include "PhysicsDebugDrawer.h"

#include "Core/Renderer.h"


using namespace physics;
using namespace core;

PhysicsDebugDrawer::PhysicsDebugDrawer( const Color& borderColor, const Color& fillColor ) :
	_borderColor( borderColor ),
	_fillColor( fillColor ),
	_pos(Transform::ZERO)
{
	//ctor
}

Transform PhysicsDebugDrawer::GetPosition() const
{
	return _pos;
}

void PhysicsDebugDrawer::SetPosition( const Transform& pos)
{
	_pos = pos;
}

void PhysicsDebugDrawer::VisitCircle( const ICircleShape* circle ) const
{
	float radius = circle->GetRadius();
	Vec2 world2 = _pos * circle->GetPos().Vec;
	Vec3 world3( world2.X, world2.Y, 0.0f );

	Renderer::DrawFilledCircle(world3, radius, _borderColor, _fillColor);
}

void PhysicsDebugDrawer::VisitPolygon( const IPolygonShape* polygon ) const
{
	IIterable<Vec2>* vertices2 = polygon->GetVertices();

	Vector<Vec3>* vertices3 = new Vector<Vec3>();

	for( IteratorPtr<Vec2> vertIter( vertices2->GetIterator( ) ); !vertIter->IsEnd( ); vertIter->Next( ) )
	{
		Vec2 vec2 = _pos * vertIter->Current();
		vertices3->Add(Vec3(vec2.X, vec2.Y, 0.0f));
	}
	Renderer::DrawFilledPolygon(vertices3, _borderColor, _fillColor);
	delete vertices3;
}
